/*
 * @Author: YeMiao 
 * @Date: 2018-03-04 09:16:07 
 * @Last Modified by: YeMiao
 * @Last Modified time: 2018-03-04 13:28:05
 */
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd';
import { UserService } from '../user.service';

@Component({
  selector: 'app-user-info',
  templateUrl: './user-info.component.html',
  styleUrls: ['./user-info.component.scss']
})
export class UserInfoComponent implements OnInit {
  validateForm: FormGroup;
  radioValue = sessionStorage.getItem('sex');

  constructor(
    private form: FormBuilder,
    private _userService: UserService,
    private _messageService: NzMessageService
  ) { }

  ngOnInit() {
    this.validateForm = this.form.group({
      user: [ sessionStorage.getItem('user') ],
      name: [ sessionStorage.getItem('name'), ],
      email: [ sessionStorage.getItem('email') ],
      phone: [ sessionStorage.getItem('phone') ],
      sex: [ sessionStorage.getItem('sex') ]
    });
  }

  _submitForm() {
    let formData = this.validateForm.value;
    this._userService.updateUser(formData).subscribe(res => {
      console.log(res);
      if(res['code'] == 1){
        this._messageService.success(res['msg']);
      }else{
        this._messageService.error(res['err']);
      }
    });
  }

}
